<!--#include file="header.html"-->
<div class="layui-row" style="margin-top: 20px;">
    <!--#include file="left.html"-->
    <div class="layui-col-md9 layui-col-md-offset1">
        <span class="layui-breadcrumb">
            <a href="/index.html">首页</a>
            <a href="/user.html">会员中心</a>
            <a href="/user.html">基本信息</a>
            <a><cite>详情</cite></a>
        </span>

        <fieldset class="layui-elem-field" style="margin-top: 20px;">
            <legend style="font-size: 14px;">用户编号</legend>
            <div class="layui-field-box" id="user_id"> </div>
        </fieldset>

        <fieldset class="layui-elem-field" style="margin-top: 40px;">
            <legend style="font-size: 14px;">用户名称</legend>
            <div class="layui-field-box" id="user_name"> </div>
        </fieldset>

        <fieldset class="layui-elem-field" style="margin-top: 40px;">
            <legend style="font-size: 14px;">最后登录IP</legend>
            <div class="layui-field-box" id="last_ip"> </div>
        </fieldset>

        <fieldset class="layui-elem-field" style="margin-top: 40px;">
            <legend style="font-size: 14px;">最后登录时间</legend>
            <div class="layui-field-box" id="last_login"> </div>
        </fieldset>

        <fieldset class="layui-elem-field" style="margin-top: 40px;">
            <legend style="font-size: 14px;">登录次数</legend>
            <div class="layui-field-box" id="login_count">  </div>
        </fieldset>

        <fieldset class="layui-elem-field" style="margin-top: 40px;">
            <legend style="font-size: 14px;">注册时间</legend>
            <div class="layui-field-box" id="register_time"> </div>
        </fieldset>

    </div>
</div>
<!--#include file="footer.html"-->
<script>
layui.use(['layer', 'jquery', 'element'], function() { 
    var $ = jQuery;

    if (!has_login()) { 
        top.location.href = "/login.html";
    }
    
    var auth_string = window.localStorage.getItem('authorization');
    $.ajax({
        url: get_api_url("auth/users/index"),
        headers: {
            "Authorization": 'Bearer ' + auth_string 
        },
        type: "GET",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function(res) { 
            if (res.code !== 0) { 
                layer.alert(res.message, function() { 
                    window.localStorage.removeItem('authorization');
                    top.location.href = '/login.html';
                });
            }  
            var result = res.result;
            $("#user_id").html(result.id);
            $("#user_name").html(result.name);
            $("#last_login").html(result.last_login);
            $("#last_ip").html(result.last_ip);
            $("#login_count").html(result.login_count);
            $("#register_time").html(result.created);
        }
    });
});
</script>
